/*
 * BaseEmptyView.java
 * classes : com.ruint.core.view.BaseEmptyView
 * @author ruint
 * V 1.0.0
 * Create at 2014-12-3 上午11:19:30
 */
package com.ruint.core.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.ruint.corelib.R;

/**
 * com.ruint.core.view.BaseEmptyView
 * 
 * @author ruint <br/>
 *         create at 2014-12-3 上午11:19:30
 */
public abstract class BaseEmptyView extends FrameLayout {

  protected Context context;
  private TextView reason;
  private TextView title;
  protected Button retry;

  public BaseEmptyView(Context context) {
    super(context);
    this.context = context;
    init();
  }

  public BaseEmptyView(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.context = context;
    init();
  }

  public BaseEmptyView(Context context, int titleId) {
    super(context);
    this.context = context;
    init();
    setFailTitle(titleId);
  }

  private void init() {
    LayoutInflater.from(context).inflate(R.layout.loadfail_layout, this);
    title = (TextView) findViewById(R.id.tv_nodata);
    reason = (TextView) findViewById(R.id.fail_reason);
    retry = (Button) findViewById(R.id.retry);
  }

  public void setFailReason(String reason) {
    this.reason.setText(reason);
    this.reason.setVisibility(View.VISIBLE);
  }

  public void setFailReason(int reasonId) {
    this.reason.setText(getResources().getString(reasonId));
    this.reason.setVisibility(View.VISIBLE);
  }

  public void setFailRetryListener(OnClickListener listener) {
    this.retry.setVisibility(View.VISIBLE);
    this.retry.setOnClickListener(listener);
  }

  public void setFailTitle(int reasonId) {
    this.title.setText(getResources().getString(reasonId));
  }

  public void setFailTitle(String reason) {
    this.title.setText(reason);
  }

  protected abstract void setBackground();

  protected abstract void setBtnSelelctor();
}
